package com.tmt.im.jpa.entity;

import com.tmt.data.jpa.entity.TmtBaseEntityId;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

import java.io.Serial;
import java.sql.Timestamp;

/**
 * 红包领取详情
 *
 * @Description TODO
 * @Author wuyi
 * @Date 2024/9/2 11:33
 * @Version 1.0
 **/
@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "red_package_detail")
@Tag(name = "RedPackageDetail", description = "红包领取详情对象")
public class RedPackageDetail extends TmtBaseEntityId {

    @Serial
    private static final long serialVersionUID = -4959820406285260761L;

    @Schema(name = "redPackageType", description = "红包类型:RedPackageType")
    @Column(nullable = false)
    private String redPackageType;

    @Schema(name = "amount", description = "领取额度，单位：分")
    @Column(nullable = false)
    private Long amount;

    @Schema(name = "memberId", description = "领取人ID, 创建时允许为空")
    private Long memberId;

    @Schema(name = "receivedAlready", description = "领取人是否已经领取了")
    private boolean receivedAlready;

    @Schema(name = "receivedTime", description = "领取时间")
    private Timestamp receivedTime;

    @Schema(name = "expireTime", description = "过期时间")
    @Column(nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Timestamp expireTime;

    @Schema(name = "refunded", description = "是否已经退款")
    @Column(nullable = false)
    private boolean refunded;

    @ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "creator_id")
    @Schema(name = "creator", description = "创建人")
    private IMUser creator;

    @ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "red_package_id")
    @Schema(name = "redPackage", description = "红包表面的文字内容")
    private RedPackage redPackage;

    @ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY)
    @JoinColumn(name = "session_id")
    @Schema(name = "session", description = "群组ID")
    private ChatSession session;

}
